import { SCREEN_WIDTH, SCREEN_HEIGHT } from '../common/constants.js'

export default class BackGround extends Sprite {
  constructor() {
    super(BG_IMG_SRC, BG_WIDTH, BG_HEIGHT);
    
    this.top = 0;
    
    // 设置渲染尺寸
    this.renderWidth = SCREEN_WIDTH;
    this.renderHeight = SCREEN_HEIGHT;
  }

  update() {
    this.top += 2;
    
    // 修改判断条件，使用确定的 this.renderHeight
    if (this.top >= this.renderHeight) {
      this.top = 0;
    }
  }

  render(ctx) {
    // 使用类的属性而不是直接使用常量
    ctx.drawImage(
      this.img,
      0,
      0,
      this.img.width,
      this.img.height,
      0,
      -this.top,
      this.renderWidth,
      this.renderHeight
    );

    ctx.drawImage(
      this.img,
      0,
      0,
      this.img.width,
      this.img.height,
      0,
      -this.top + this.renderHeight,
      this.renderWidth,
      this.renderHeight
    );
  }
} 